<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title></title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
    </style>
</head>

<body class="iframeBody">
    <div class="Wrapper">
      <form id="formSet">

      <div class="sqPanel">
          <div class="sqPanel_head">
              <div class="btnsBox posL">
                <%--<span id="refreshBtn" class="sq-button sq-button-round">刷新</span>--%>
                <span id="addBtn" class="sq-button sq-button-round">新增</span>
                <span id="addGuacheBtn" class="sq-button sq-button-round">新增挂车</span>
                <span id="detailBtn" class="sq-button sq-button-round">删除</span>
              </div>
              <div>&nbsp;&nbsp;&nbsp;</div>
          </div>
          <div class="sqPanel_body">
              <div class="fieldBox">
                  <p style="color: #dd0000">系统自动计算调节费后，将自动将调节费累加至设备款和首期中，如对调节费有异议，可删除设备重新报价</p>
                  <br>
              </div>
            <div id="grid_chanpin" class="sq-grid"></div>
          </div>
      </div>
          <div class="fieldset1 tabel_col clearFix">
              <div class="caption">
                  <span class="title">客户信息</span>
              </div>
              <div class="fieldBox col_33">
                  <div class="label">是否农民</div>
                  <div class="field">
                      <select name="isFarmer" id="isFarmer" data-value="" validate="{required:true, select: true}" ligerui="{width: 60}">
                          <option value="0" selected>否</option>
                          <option value="1">是</option>
                      </select>
                  </div>
              </div>
          </div>
        <div class="fieldset1 tabel_col clearFix">
            <div class="caption">
                <span class="title">报价信息</span>
                <input name="routeId" id="routeId" type="hidden" class="ui-textbox"   value="${insRouteBscInfoVO.id}" >
            </div>
            <div class="fieldBox col_33">
                <div class="label">合同总额(元)</div>
                <div class="field">
                    <input name="contAmt" id="contAmt" type="text" readonly="readonly" class="ui-textbox" value="${insRouteBscInfoVO.contAmt}" validate="{required:true}">
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否包牌</div>
                <div class="field">
                    <select name="isBp" id="isBp" validate="{required:true}">
                        <option value="" selected="selected">--请选择--</option>
                        <c:forEach items="${isBpList}" var="bp">
                            <option value="${bp.key}">${bp.value}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">租赁期数</div>
                <div class="field">
                    <input name="lsPd" id="lsPd" type="text" class="ui-textbox" value="${insRouteBscInfoVO.lsPd}" ligerui="{width: 60}" validate="{required:true,number:true}">
                    <select name="lsPdUntCd" id="lsPdUntCd" validate="{required:true}">
                        <option value="" selected="selected">--请选择--</option>
                        <c:forEach items="${lsPdUntCdList}" var="lsPdUntCd">
                            <option value="${lsPdUntCd.key}">${lsPdUntCd.value}</option>
                        </c:forEach>
                    </select>

                    <!-- <input type="text" name="testCombo" id="testCombo" placeholder="请选择" ltype="combobox" ligerui="{width: 60}"> -->
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">租赁年利率</div>
                <div class="field">
                    <input name="annIntRatePct" id="annIntRatePct" type="text" class="ui-textbox" value="${insRouteBscInfoVO.annIntRatePct}" validate="{required:true,number:true}">%
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否前置利息</div>
                <div class="field">
                    <select name="isPreInt" id="isPreInt" data-value="" validate="{required:true, select: true}" ligerui="{width: 60}">
                        <option value="0" selected>否</option>
                        <option value="1">是</option>
                    </select>
                </div>
            </div>
        </div>

        <div id="grid_baojia" class="sq-grid"></div>

        <div class="fieldset1 tabel_col clearFix">
            <div class="caption">
                <span class="title">发票信息</span>
            </div>
            <div class="fieldBox col_33">
                <div class="label">主票金额（元）</div>
                <div class="field">
                    <input name="fee63" id="fee63" type="text" class="ui-textbox" value="${fee63}" validate="{required:true}">
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">补票金额（元）</div>
                <div class="field">
                    <input name="fee64" id="fee64" type="text" class="ui-textbox" readonly="readonly" value="${fee64}" validate="{required:true}">
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否已开票</div>
                <div class="field">
                    <select name="isCheckOut" id="isCheckOut" data-value="" validate="{required:true, select: true}" ligerui="{width: 60}">
                        <option value="0" selected>否</option>
                        <option value="1">是</option>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33" id = "checkOutDtdiv">
                <div class="label">开票时间</div>
                <div class="field">
                    <input name="checkOutDt" id="checkOutDt" type="text" class="ui-datepicker"  value="${insRouteBscInfoVO.checkOutDt}">
                </div>
            </div>
        </div>



        <div class="fieldset1 tabel_col clearFix">
            <div class="caption">
                <span class="title">上牌信息</span>
            </div>
            <div class="fieldBox col_33">
                <div class="label">上牌城市</div>
                <div class="field">
                    <jsp:include page="../../system/sysRegion/region.jsp" flush="true">
                        <jsp:param name="regionShowLvl"  value="2"/>
                    </jsp:include>
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否已上牌</div>
                <div class="field">
                    <select name="isLic" id="isLic" data-value="" validate="{required:true, select: true}" ligerui="{width: 60}">
                        <option value="0" selected>否</option>
                        <option value="1">是</option>
                    </select>
                </div>
            </div>
            <div class="fieldBox col_33" id = "licDtdiv">
                <div class="label">上牌时间</div>
                <div class="field">
                    <input name="licDt" id="licDt" type="text" class="ui-datepicker" value="">
                </div>
            </div>
            <div class="fieldBox col_33">
                <div class="label">是否再次上牌</div>
                <div class="field">
                    <select name="isLicAgain" id="isLicAgain" data-value="" validate="{required:true, select: true}" ligerui="{width: 60}">
                        <option value="0" selected>否</option>
                        <option value="1">是</option>
                    </select>
                </div>
                </div>
            <div class="fieldBox col_33" id = "licAgainDtdiv">
                <div class="label">再次上牌时间</div>
                <div class="field">
                    <input name="licAgainDt" id="licAgainDt" type="text" class="ui-datepicker" value="${insRouteBscInfoVO.licAgainDt}">
                </div>
            </div>
        </div>
        <div class="btnsBox">
          <span id="clearBtn" class="sq-button sq-button-round co_normal">清空</span>
          <span id="filterBtn" class="sq-button sq-button-round">筛选</span>
        </div>
      </form>
        <div id="detailres_div" style="display:none">
            <div id="grid_heguijigouDetail" class="sq-grid"></div>
            <br>
            <div id="grid_heguijigouUnDetail" class="sq-grid"></div>
            <br>
        </div>
        <div id="res_div" style="display:none">
            <div class="btnsBox">
                <span id="isAllowNonIns" class="sq-button sq-button-round"></span>
                <span id="applySpecial" class="sq-button sq-button-round">申请特批</span>
            </div>
            <div id="grid_heguijigou" class="sq-grid"></div>
            <div id="defaultTip" class="fieldBox">
                <br>
                <p>点击【确认】筛选页面信息才会保存哦</p>
                <p>存在合规机构但是需要做非资管业务的情况，请点击【申请特批】按钮发起特批流程进行审批</p>
                <br>
            </div>
            <div id="defaultText" class="fieldBox" style="display: none">
                <p>暂无符合情况的资管机构，点击确认提交非资管业务</p>
                <br>
            </div>
            <div id="grid_heguijigouUn" class="sq-grid" STYLE="display: none"></div>
            <div class="btnsBox TC">
                <span id="confirmBtn" class="sq-button sq-button-round">确认</span>
            </div>
        </div>
    </div>

    <form id="capFundConfirm_form" style="display: none;">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <p>您尚未选择任一合规资金方，请选择。</p>
                <p>如因特殊原因不选择任一资方，请填写原因提交资管业务特批申请。</p>
                <br>
            </div>
            <div class="fieldBox">
                <div class="label">申请原因：</div>
                <div class="field">
                    <textarea name="docketRem" id="docketRem" class="ui-textarea l-textarea"
                              rows="7" cols="60" style="width: 300px;" validate="{required:false,maxlength:200}"></textarea>
                </div>
            </div>
            <div class="fieldBox col_100">
                <div class="label">资料上传</div>
                <div class="field">
                    <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload2.jsp" flush="true" >
                        <jsp:param name="filePath" value="insroute"/>
                    </jsp:include>
                </div>
            </div>
        </div>
    </form>

    <form id="confirm_form" style="display: none;">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <p>按此修改机构信息将会：</p>
                <p>1.删除现有报价及支付表</p>
                <p>2.删除银行卡信息和资方开户信息</p>
                <p>确定修改吗？</p>
                <br>
            </div>
        </div>
    </form>

    <script>
    var arrFoundCode = [];
    <c:forEach items="${friBaseList}" var= "module">
    var item  = {"fundRasInsId":"${module.id}","fundRasInsNmShow":"${module.fundRasInsNmShow}"};
    arrFoundCode.push(item);
    </c:forEach>

    var prjId = "${prjId}";
    var prjTypCd = "${prjTypCd}";
    var buOrgCd = "${buOrgCd}";
    var isAllowNonIns = "${isAllowNonIns}";
    var isCheckRouteFlag = "${isCheckRouteFlag}";
    var isSplMfr = "${isSplMfr}";
    var isFilterReady = CommonConstant.C_YN_N;
    var comboBoxeList = ${comboBoxeList};
    var comboBoxeData = {};
    comboBoxeData["Rows"] = comboBoxeList;
    comboBoxeData["Total"] = comboBoxeList.length;
    var detailFlag = '${detailFlag}';
    var editFlag = true;
    var checkVal = '';
    var calBaseCdListJSON = [];
    var preInsId = "${preInsId}";
    var stats = false;
    var isBigCstWork = '${isBigCstWork}' ;
    var dsCd = '${dsCd}' ;
    <c:if test="${not empty calBaseCdList}"> calBaseCdListJSON = ${calBaseCdList}; </c:if>
    $(function() {
        $("#formSet").ligerForm({
            validate: true
        });
        $('#isCheckOut').on('change', function(event) {
            contrlData();
        });
        $('#isLic').on('change', function(event) {
            contrlData();
        });
        $('#isLicAgain').on('change', function(event) {
            contrlData();
        });
        $('#fee63').on('change', function(event) {
            if(($("#contAmt").val() - $('#fee63').val()) < 0){
                $("#fee64").val(0);
            }else {
                $("#fee64").val(($("#contAmt").val() - $('#fee63').val()).toFixed(2));
            }
        });
        $('#annIntRatePct').toFixNumber(10,
            {
                onToFix: function () {
                    $.ligerDialog.SQalert({SQ_type: "warning", content: "小数点后不要超过"+10+"位数！"});
                }
            }
        );
        if(isBigCstWork == '1' && dsCd == 'CHL0047'){  // 金诚系统报单的大客户业务不可添加/删除车辆
            $("#addBtn").hide() ;
            $("#addGuacheBtn").hide() ;
            $("#detailBtn").hide() ;
        }
        var annIntRatePct = Number($('#annIntRatePct').val());
        $('#annIntRatePct').val(toNonExponential(annIntRatePct));
        var ligerGrid_chanpin;
        var ligerGrid_baojia;
        if(detailFlag == 'true'){
            editFlag = false;
        }
        if(CommonConstant.C_YN_Y == isSplMfr && buOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZK){
            if (liger.get("lsPd")) {
                liger.get("lsPd").setDisabled(true);
            }
            if (liger.get("lsPdUntCd")) {
                liger.get("lsPdUntCd").setDisabled(true);
            }
            if (liger.get("annIntRatePct")) {
                liger.get("annIntRatePct").setDisabled(true);
            }
            ligerGrid_baojiaload(false);
        }else{
            ligerGrid_baojiaload(editFlag);
        }
        ligerGrid_chanpinload(editFlag);
        function ligerGrid_chanpinload(editFlag){
            ligerGrid_chanpin = $("#grid_chanpin").ligerGrid({
                url: '<%=path%>/insroute/insRoutePrdInfo/initRoutePrdInfo.do?prjId=' + prjId,
                method: 'get',
                columns: [
                    {
                        display: '产品品牌', name: 'brId', minWidth: 200,
                        valueField: 'brId',
                        textField: 'brCd',
                        editor: {
                            type: 'popup', valueField: 'key', textField: 'value', grid:
                                {
                                    data: comboBoxeData, columns: [
                                        { name: 'value', width: 400, display: '产品品牌' }
                                    ]
                                },
                            condition: {
                                prefixID: 'condtion_',
                                fields: [
                                    { name: 'value', type: 'text', label: '产品品牌', width: 200 }
                                ]
                            }, onSelected: f_onSelected,
                            searchClick: function (e)
                            {
                                e.grid.loadData($.ligerFilter.getFilterFunction(e.rules));
                            }
                        },

                        /*render: function (item)
                        {
                            return item.pinpaiText;
                        }*/
                    },
                    {
                        display: '车系/产品名称', name: 'modelId', minWidth: 200,
                        valueField: 'modelId',
                        textField: 'modelNm',
                        editor: {
                            type: 'select',
                            data: '',
                            valueField: 'key',
                            textField: 'value',
                            // readonly: true
                        },
                        /*render: function (item)
                        {
                            return item.chexiText;
                        }*/
                    },
                    {
                        display: '用途', name: 'prdId', minWidth: 200,
                        valueField: 'prdId',
                        textField: 'prdNm',
                        editor: {
                            type: 'select',
                            data: "",
                            valueField: 'key',
                            textField: 'value',
                            // readonly: true
                        },
                        /*render: function (item)
                        {
                            return item.yongtuText;
                        }*/
                    },
                    {
                        display: '预估车价（元）', name: 'guidePc', width: 200, align: 'right',
                        editor: {type: 'number',
                            precision: 2,
                            toFix: true,
                            onToFix: function () {
                                $.ligerDialog.SQalert({
                                    SQ_type: "warning",
                                    content: "小数点后面最多2位！"
                                });
                            }
                        },
                        /*render: function (item) {
                            var h = '&yen; ' + SQ.utils.currencyFormatter(item.amount, 2)
                            return h;
                        },*/
                    },
                    { display: '设备数量', name: 'prdQty', width: 100 , editor: {type: 'digits'}},
                    { display: '调节费', name: 'mediationFeeAmt', width: 100},
                ],
                onBeforeEdit: function (e) {
                    var colNanme = e.column.columnname;
                    if(colNanme == "brId"){
                        checkVal = e.record.brId;
                    }else if(colNanme == "modelId"){
                        checkVal = e.record.modelId;
                    }else if(colNanme == "prdId" && e.record.prdCd == "2"){
                        checkVal = e.record.prdId;
                    }
                    if(colNanme != "guidePc" && (isBigCstWork == '1' && dsCd == 'CHL0047')){
                        e.column.editor.readonly=true;
                        return false ;
                    }
                    if(colNanme == "modelId" && e.record.prdCd != "2"){
                        $.ajax({
                            type: 'get',
                            dataType:'json',
                            async:false,
                            url: '<%=path%>/project/vehicle/carModel.do?brandId=' +e.record.brId,
                            success:function(data){
                                e.column.editor.data=data;
                            }
                        });
                    }
                    if((colNanme == "brId" || colNanme == "modelId") && e.record.prdCd == "2"){
                        e.column.editor.readonly=true;
                    }else{
                        e.column.editor.readonly=false;
                    }
                    if(colNanme == "prdId" && e.record.prdCd != "2"){
                        $.ajax({
                            type: 'get',
                            dataType:'json',
                            async:false,
                            url: '<%=path%>/project/vehicle/carUsage.do?modelId=' +e.record.modelId ,
                            success:function(data){
                                e.column.editor.data=data;
                            }
                        });
                    }else if(colNanme != "brId" && colNanme != "modelId" && e.record.prdCd == "2"){
                        $.ajax({
                            type: 'get',
                            dataType:'json',
                            async:false,
                            url: '<%=path%>/vehicle/trailer/trailerUsageList.do',
                            success:function(data){
                                e.column.editor.data=data;
                            }
                        });
                    }
                    if(colNanme == "brId" && e.record.prdCd != "2"){
                        e.column.editor.data=comboBoxeList;
                    }
                    setTimeout(function(){SetIframe_height();},0)
                },
                onAfterEdit: function (e) {
                    var colNanme = e.column.columnname;
                    var recordnew  = e.record;
                    if(colNanme == "brId"){
                        if(checkVal != e.record.brId){
                            recordnew.modelId = '';
                            recordnew.modelNm = '';
                            recordnew.prdId = '';
                            recordnew.prdNm = '';
                            ligerGrid_chanpin.updateRow(e.record,recordnew);
                        }
                    }else if(colNanme == "modelId"){
                        if(checkVal != e.record.modelId){
                            recordnew.prdId = '';
                            recordnew.prdNm = '';
                            ligerGrid_chanpin.updateRow(e.record,recordnew);
                        }
                    }else if(colNanme == "prdId" && e.record.prdCd == "2"){
                        if(checkVal != e.record.prdId){
                            recordnew.brId = '';
                            recordnew.brCd = '';
                            recordnew.modelId = '';
                            recordnew.modelNm = '';
                            ligerGrid_chanpin.updateRow(e.record,recordnew);
                        }
                    }
                    checkVal = "";
                    if(colNanme == "guidePc" || colNanme == "prdQty" ){
                        var chanpin = ligerGrid_chanpin.getData();
                        var cat = 0;
                        for (index in chanpin){
                            var guidPc = chanpin[index].guidePc;
                            var prdQty = chanpin[index].prdQty;
                            cat += guidPc*prdQty;
                        };
                        $("#contAmt").val(cat);
                        var rows = ligerGrid_baojia.rows;
                        var calBaseCd = rows[1].calBaseCd;
                        var fee01 = rows[0].feePct * cat/100;
                        var fee02 = 0;
                        if(calBaseCd == 2){
                            fee02 = rows[1].feePct * (cat-fee01)/100;
                        }else{
                            fee02 = rows[1].feePct * cat/100;
                        }
                        ligerGrid_baojia.updateCell("feeAmt",fee01,rows[0]);
                        ligerGrid_baojia.updateCell("feeAmt",fee02,rows[1]);
                        if((cat-$("#fee63").val())<0){
                            $("#fee64").val(0);
                        }else{
                            $("#fee64").val((cat-$("#fee63").val()).toFixed(2));
                        }
                    }
                    if(colNanme == "prdQty" ){
                        if(checkVal != e.record.prdId){
                            recordnew.mediationFeeAmt = e.record.mediationFeeAmtAvg * e.record.prdQty;
                            ligerGrid_chanpin.updateRow(e.record,recordnew);
                        }
                    }
                },
                onBeforeSubmitEdit: function (e) {
                },
                pageSize: 10,
                root: 'rows',
                record: 'total',
                hideLoadButton: true,
                width: '100%',
                height: 300,
                heightDiff: -2,
                enabledEdit: editFlag,
                isScroll: false,
                checkbox: true,
                frozen: false,
                rownumbers: true,
                allowUnSelectRow: true,
                alternatingRow: false,
                enabledSort: false, // 增加行的时候，出现问题，所以不过滤了
                fixedCellHeight: false,
                usePager: false,
                onAfterShowData: function() {
                    SetIframe_height();
                }
            });
        }

        function ligerGrid_baojiaload(editFlag){
            ligerGrid_baojia = $("#grid_baojia").ligerGrid({
                url: '<%=path%>/insroute/insRoutePrpsFee/initRoutePrpsFee.do?prjId=' + prjId,
                method: 'get',
                columns: [
                    {
                        display: '费用类型', name: 'feeTypCdNm', minWidth: 200
                    },
                    {
                        display: '计算基数', name: 'calBaseCd', minWidth: 200,
                        editor: {
                            type: 'select',
                            data: calBaseCdListJSON,
                            valueField: 'key',
                            textField: 'value'
                        },
                        valueField: 'calBaseCd',
                        textField: 'calBaseCdNm',
                        render: function (item) {
                            return item.calBaseCdNm;
                        }
                    },
                    { display: '比例值（%）', name: 'feePct', width: 100 ,
                        editor: {type: 'number',
                            precision: 8,
                            toFix: true,
                            onToFix: function () {
                                $.ligerDialog.SQalert({
                                    SQ_type: "warning",
                                    content: "小数点后面最多8位！"
                                });
                            }
                        },
                        render: function (item) {
                            item.feePct = Number(item.feePct);
                            if(typeof item.feePct =='number'){
                                var pct =  (parseFloat(item.feePct)).toFixed(2)
                                return pct;
                            }
                        }
                    },
                    // { display: '金额（元）', name: 'amount', minWidth: 140 , editor: {type: 'float'}},
                    {
                        display: '金额（元）', name: 'feeAmt', width: 200, align: 'right',
                        editor: {type: 'number',
                            precision: 2,
                            toFix: true,
                            onToFix: function () {
                                $.ligerDialog.SQalert({
                                    SQ_type: "warning",
                                    content: "小数点后面最多2位！"
                                });
                            }
                        },
                        render: function (item) {
                            var h = '&yen; ' + SQ.utils.currencyFormatter(item.feeAmt, 2)
                            return h;
                        },
                    },
                    {
                        display: '计入方式', name: 'cntWayCdNm', minWidth: 200
                    },
                ],
                onBeforeEdit: function (e) {
                    if(e.record.isAllowChg==0){
                        e.column.editor.readonly = true;
                    }else{
                        e.column.editor.readonly = false;
                    }
                    setTimeout(function(){SetIframe_height();},0)
                },
                onAfterEdit: function (e) {
                    var colNanme = e.column.columnname;
                    var rows = ligerGrid_baojia.rows;
                    var calBaseCd = rows[1].calBaseCd;
                    if(colNanme == "feePct" && (e.record.feeTypCdNm == "首期" || e.record.feeTypCdNm == "客户保证金")){
                        var contAmt = $("#contAmt").val();
                        var fee01 = (rows[0].feePct * contAmt/100).toFixed(2);
                        var fee02 = 0;
                        if(calBaseCd == 2){
                            fee02 = (rows[1].feePct * (contAmt-fee01)/100).toFixed(2);
                        }else{
                            fee02 = (rows[1].feePct * contAmt/100).toFixed(2);
                        }
                        ligerGrid_baojia.updateCell("feeAmt",fee01,rows[0]);
                        ligerGrid_baojia.updateCell("feeAmt",fee02,rows[1]);
                    }
                    if(colNanme == "feeAmt" && (e.record.feeTypCdNm == "首期" || e.record.feeTypCdNm == "客户保证金")){
                        var contAmt = $("#contAmt").val();
                        if(contAmt != 0){
                            if(e.record.feeTypCdNm == "首期"){
                                var fee01 = ((rows[0].feeAmt / contAmt)*100).toFixed(8);
                                if(calBaseCd == 2){
                                    fee02 = (rows[1].feePct*(contAmt-rows[0].feeAmt)/100).toFixed(2);
                                }else{
                                    fee02 = (rows[1].feePct*contAmt/100).toFixed(2);
                                }
                                ligerGrid_baojia.updateCell("feePct",fee01,rows[0]);
                                ligerGrid_baojia.updateCell("feeAmt",fee02,rows[1]);
                            }else{
                                var fee02 = 0;
                                if(calBaseCd == 2){
                                    fee02 = ((rows[1].feeAmt / (contAmt-rows[0].feeAmt))*100).toFixed(8);
                                }else{
                                    fee02 = ((rows[1].feeAmt / contAmt)*100).toFixed(8);
                                }
                                ligerGrid_baojia.updateCell("feePct",fee02,rows[1]);
                            }
                        }else{
                            ligerGrid_baojia.updateCell("feePct",0,rows[0]);
                            ligerGrid_baojia.updateCell("feePct",0,rows[1]);
                        }
                    }
                    if(colNanme == "calBaseCd" && (e.record.feeTypCdNm == "客户保证金")){
                        var contAmt = $("#contAmt").val();
                        var fee01 = (rows[0].feePct * contAmt/100).toFixed(2);
                        var fee02 = 0;
                        if(calBaseCd == 2){
                            fee02 = (rows[1].feePct * (contAmt-fee01)/100).toFixed(2);
                        }else{
                            fee02 = (rows[1].feePct * contAmt/100).toFixed(2);
                        }
                        ligerGrid_baojia.updateCell("feeAmt",fee01,rows[0]);
                        ligerGrid_baojia.updateCell("feeAmt",fee02,rows[1]);
                    }
                    if(colNanme == "calBaseCd" && (e.record.feeTypCdNm == "首期")){
                        if(rows[0].calBaseCd == 2){
                            top.$.ligerDialog.SQalert({content: "首期计入方式只能是合同额", SQ_type: "warning"});
                        }
                    }
                },
                onBeforeSubmitEdit: function (e) {
                },
                pageSize: 10,
                root: 'rows',
                record: 'total',
                hideLoadButton: true,
                width: '100%',
                height: 300,
                heightDiff: -2,
                enabledEdit: editFlag,
                isScroll: false,
                // checkbox: true,
                frozen: false,
                rownumbers: true,
                allowUnSelectRow: true,
                alternatingRow: false,
                enabledSort: false, // 增加行的时候，出现问题，所以不过滤了
                fixedCellHeight: false,
                usePager: false,
                onAfterShowData: function() {
                    SetIframe_height();
                }
            });
        }

        $('#addBtn').on('click', function(event) {
            event.preventDefault();
            ligerGrid_chanpin.addRow({
                "brId": "",
                "brCd": "",
                "modelId": "",
                "modelNm": "",
                "prdId": "",
                "prdNm": "",
                "guidePc":0,
                "prdQty":1,
                "mediationFeeAmt":0,
                "mediationFeeAmtAvg":0
            });
        });
        $('#addGuacheBtn').on('click', function(event) {
            event.preventDefault();
            ligerGrid_chanpin.addRow({
                "brId": "",
                "brCd": "",
                "modelId": "",
                "modelNm": "",
                "prdId": "",
                "prdNm": "",
                "prdTypCd":"9",
                "prdCd":"2",
                "guidePc":0,
                "prdQty":1,
                "mediationFeeAmt":0,
                "mediationFeeAmtAvg":0
            });
        });
        function f_onSelected(e) {
            if (!e.data || !e.data.length) return;
            var selected = e.data[0];
            var newRow = ligerGrid_chanpin.lastEditRow;
            newRow.brId = selected.key;
            newRow.brCd = selected.value;
            ligerGrid_chanpin.updateRow(ligerGrid_chanpin.lastEditRow, newRow);
            var out = JSON.stringify(selected);
            $("#message").html('最后选择:'+out);
        }

        $('#detailBtn').on('click', function(event) {
            event.preventDefault();
            var selectedRows = ligerGrid_chanpin.getSelectedRows();
            if(selectedRows.length != 1){
                top.$.ligerDialog.SQalert({content: "请选中一条要删除的数据", SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            ligerGrid_chanpin.remove(selectedRows[0]);
            var guidePc = selectedRows[0].guidePc;
            var prdQty = selectedRows[0].prdQty;
            cat = $("#contAmt").val() - guidePc*prdQty;
            $("#contAmt").val(cat);
            var rows = ligerGrid_baojia.rows;
            var calBaseCd = rows[1].calBaseCd;
            ligerGrid_baojia.updateCell("feeAmt",rows[0].feePct * cat/100,rows[0]);
            if(calBaseCd == 2){
                var fee01 = rows[0].feePct * cat/100;
                ligerGrid_baojia.updateCell("feeAmt",rows[1].feePct * (cat-fee01)/100,rows[1]);
            }else{
                ligerGrid_baojia.updateCell("feeAmt",rows[1].feePct * cat/100,rows[1]);
            }
            if((cat-$("#fee63").val())<0){
                $("#fee64").val(0);
            }else{
                $("#fee64").val((cat-$("#fee63").val()).toFixed(2));
            }
        });

        $("#clearBtn").on('click', function(event) {
            var ligerForm = liger.get("formSet");
            ligerForm.setData({
                isFarmer:0,
                isPreInt:0,
                isCheckOut: 0,
                isLic: 0,
                isLicAgain: 0,
                checkOutDt: "",
                licDt: "",
                licAgainDt: "",
                fee63:0,
                fee64:0,
                rgnProvCd: "",
                rgnCityCd: "",
                lsPd: "",
                lsPdUntCd: 1,
                annIntRatePct: 0,
                isBp: 0,
                contAmt:0
            });
            $("#checkOutDtdiv").hide();
            $("#licDtdiv").hide();
            $("#licAgainDtdiv").hide();
            var rowsBj = ligerGrid_baojia.rows;
            if(rowsBj.length>0){
                for(var i = 0; i<rowsBj.length; i++){
                    ligerGrid_baojia.updateCell("feeAmt",0,rowsBj[i]);
                    ligerGrid_baojia.updateCell("feePct",0,rowsBj[i]);
                }
            }
            var rowsCp = ligerGrid_chanpin.rows;
            if(rowsCp.length>0){
                for(var i = 0; i<rowsCp.length; i++){
                    ligerGrid_chanpin.updateCell("guidePc",0,rowsCp[i]);
                    ligerGrid_chanpin.updateCell("prdQty",0,rowsCp[i]);
                }
            }
        });


        var ligerGrid_heguijigoudetail = $("#grid_heguijigouDetail").ligerGrid({
            url: '<%=path%>/insroute/insRouteInsRes/routeRes.do',
            method : 'post',
            parms:{
                prjId:prjId,
                sts:CommonConstant.C_YN_Y
            },
            columns: [
                { display: '合规机构名称', name: 'insNm', width: 300,
                    render: function (rowdata, rowindex, value) {
                        if(arrFoundCode){
                            for (var i=0;i<arrFoundCode.length;i++) {
                                if(arrFoundCode[i].fundRasInsId == rowdata.insId){
                                    return  arrFoundCode[i].fundRasInsNmShow;
                                }
                            }
                        }
                    }
                },
                { display: '提示信息', name: 'gctDes', align: 'left',
                    render:function(rowdata,rowindex,value){
                        if(rowdata.gctDes!=null){
                            return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.gctDes + '">' + rowdata.gctDes + '</span>';
                        }
                    }
                },
                { display: '追加调节费', name: 'feeDes', align: 'left',
                    render:function(rowdata,rowindex,value){
                        if(rowdata.feeDes!=null){
                            return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.feeDes + '">' + rowdata.feeDes + '</span>';
                        }
                    }
                },
            ],
            pageSize:10,
            hideLoadButton : true,
            width: '100%',
            root: 'rows',
            record: 'total',
            // height: 250,
            checkbox:false,
            rownumbers:true,
            usePager: false,
            frozen: false,
            fixedCellHeight: false,
            isSingleCheck: true,
            isChecked:function(item){
                if (item.isChecked == CommonConstant.C_YN_Y)
                    return true;
                return false;
            },
            isDisabledSelect: function (item) {
                if (item.Country == 'UK' || item.Country == 'Mexico') return true;
            },
            onAfterShowData: function (item) {
                SetIframe_height ();
            },
            onLoaded:function(){
                this.toggleLoading(false);
            }
        });
        var ligerGrid_heguijigouUndetail = $("#grid_heguijigouUnDetail").ligerGrid({
            url: '<%=path%>/insroute/insRouteInsRes/routeRes.do',
            method : 'post',
            parms:{
                prjId:prjId,
                sts:CommonConstant.C_YN_N
            },
            columns: [
                { display: '不合规机构名称', name: 'insNm', width: 300,
                    render: function (rowdata, rowindex, value) {
                        if(arrFoundCode){
                            for (var i=0;i<arrFoundCode.length;i++) {
                                if(arrFoundCode[i].fundRasInsId == rowdata.insId){
                                    return  arrFoundCode[i].fundRasInsNmShow;
                                }
                            }
                        }
                    }
                },
                { display: '提示信息', name: 'gctDes', align: 'left',
                    render:function(rowdata,rowindex,value){
                        if(rowdata.gctDes!=null){
                            return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.gctDes + '">' + rowdata.gctDes + '</span>';
                        }
                    }
                },
            ],
            pageSize:10,
            hideLoadButton : true,
            width: '100%',
            root: 'rows',
            record: 'total',
            // height: 250,
            checkbox:false,
            rownumbers:true,
            usePager: false,
            frozen: false,
            fixedCellHeight: false,
            isSingleCheck: true,
            isDisabledSelect: function (item) {
                if (item.Country == 'UK' || item.Country == 'Mexico') return true;
            },
            onAfterShowData: function () {
                SetIframe_height ();
            },
            onLoaded:function(){
                this.toggleLoading(false);
            }
        });


        var ligerGrid_heguijigou = $("#grid_heguijigou").ligerGrid({
            url: '<%=path%>/insroute/insRouteBscInfo/insRoute.do',
            method : 'post',
            parms:{
                sts:CommonConstant.C_YN_Y
            },
            columns: [
                { display: '合规机构名称', name: 'insNm', width: 300 ,
                    render: function (rowdata, rowindex, value) {
                        if(arrFoundCode){
                            for (var i=0;i<arrFoundCode.length;i++) {
                                if(arrFoundCode[i].fundRasInsId == rowdata.insId){
                                    return  arrFoundCode[i].fundRasInsNmShow;
                                }
                            }
                        }
                    }
                },
                { display: '提示信息', name: 'gctDes', align: 'left',
                    render:function(rowdata,rowindex,value){
                        if(rowdata.gctDes!=null){
                            return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.gctDes + '">' + rowdata.gctDes + '</span>';
                        }
                    }
                },
                { display: '追加调节费', name: 'feeDes', align: 'left',
                    render:function(rowdata,rowindex,value){
                        if(rowdata.feeDes!=null){
                            return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.feeDes + '">' + rowdata.feeDes + '</span>';
                        }
                    }
                },
            ],
            pageSize:10,
            hideLoadButton : true,
            width: '100%',
            root: 'rows',
            record: 'total',
            // height: 250,
            checkbox:true,
            rownumbers:true,
            usePager: false,
            frozen: false,
            fixedCellHeight: false,
            isSingleCheck: true,
            isChecked:function(item){
                if (item.isChecked == CommonConstant.C_YN_Y)
                    return true;
                return false;
            },
            isDisabledSelect: function (item) {
                if (item.Country == 'UK' || item.Country == 'Mexico') return true;
            },
            onAfterShowData: function (item) {
                SetIframe_height ();
            },
            onLoaded:function(){
                this.toggleLoading(false);
            },
            onsuccess:function (data) {
                if(data.rows.length>0){
                    isAllowNonIns = data.rows[0].isAllowNonIns;
                    if(isAllowNonIns == CommonConstant.C_YN_Y){
                        $("#isAllowNonIns").html("特批标识：是");
                    }else{
                        $("#isAllowNonIns").html("特批标识：否");
                    }
                    for (index in data.rows) {
                        if(data.rows[index].isShowBiz == CommonConstant.C_YN_N){
                            ligerGrid_heguijigou.deleteRow(data.rows[index]);
                        }
                    }
                }
            }
        });
        var ligerGrid_heguijigouUn = $("#grid_heguijigouUn").ligerGrid({
            url: '<%=path%>/insroute/insRouteBscInfo/insRoute.do',
            method : 'post',
            parms:{
                sts:CommonConstant.C_YN_N
            },
            columns: [
                { display: '不合规机构名称', name: 'insNm', width: 300,
                    render: function (rowdata, rowindex, value) {
                        if(arrFoundCode){
                            for (var i=0;i<arrFoundCode.length;i++) {
                                if(arrFoundCode[i].fundRasInsId == rowdata.insId){
                                    return  arrFoundCode[i].fundRasInsNmShow;
                                }
                            }
                        }
                    }
                },
                { display: '提示信息', name: 'gctDes', align: 'left',
                    render:function(rowdata,rowindex,value){
                        if(rowdata.gctDes!=null){
                            return '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.gctDes + '">' + rowdata.gctDes + '</span>';
                        }
                    }
                },
            ],
            pageSize:10,
            hideLoadButton : true,
            width: '100%',
            root: 'rows',
            record: 'total',
            // height: 250,
            checkbox:false,
            rownumbers:true,
            usePager: false,
            frozen: false,
            fixedCellHeight: false,
            isSingleCheck: true,
            isDisabledSelect: function (item) {
                if (item.Country == 'UK' || item.Country == 'Mexico') return true;
            },
            onAfterShowData: function () {
                SetIframe_height ();
            },
            onLoaded:function(){
                this.toggleLoading(false);
            },
            onsuccess:function (data) {
                if(data.rows.length>6){
                    $("#defaultText").show();
                    $("#defaultTip").hide();
                }else{
                    $("#defaultText").hide();
                    $("#defaultTip").show();
                }
                if(data.rows.length>0){
                    isAllowNonIns = data.rows[0].isAllowNonIns;
                    if(isAllowNonIns == CommonConstant.C_YN_Y){
                        $("#isAllowNonIns").html("特批标识：是");
                    }else{
                        $("#isAllowNonIns").html("特批标识：否");
                    }
                    for (index in data.rows) {
                        if(data.rows[index].isShowBiz == CommonConstant.C_YN_N){
                            ligerGrid_heguijigouUn.deleteRow(data.rows[index]);
                        }
                    }
                }
            }
        });
        $('#filterBtn').click(function(event) {
            var flag = validInfo();
            if(flag == false){
                return false;
            }
            $.ligerDialog.SQopen({
                width: 800,
                top: 100,
                buttons: [
                    {
                        text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
                            $.ligerDialog.hide();
                        }
                    }
                ],
                title : '机构筛选结果',
                target: $("#res_div")
            });
            if(isAllowNonIns == CommonConstant.C_YN_Y){
                $("#isAllowNonIns").html("特批标识：是");
            }else{
                $("#isAllowNonIns").html("特批标识：否");
            }
            $("#grid_heguijigouUn").show();
            var ligerForm = liger.get("formSet");
            if (!ligerForm.valid()) {
                top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = ligerForm.getData();
            var carInfoList = JSON.stringify(ligerGrid_chanpin.getData());
            var feeList = JSON.stringify(ligerGrid_baojia.getData());
            data["id"] = $("#routeId").val();
            data["prjId"] = prjId;
            data["carInfoList"] = carInfoList;
            data["feeList"] = feeList;
            data["flag"] = CommonConstant.C_YN_Y;
            data["channel"] = CommonConstant.C_YN_N;
            for (name in data){
                ligerGrid_heguijigou.setParm(name,data[name]);
                ligerGrid_heguijigouUn.setParm(name,data[name]);
            };
            ligerGrid_heguijigou.reload();
            ligerGrid_heguijigouUn.reload();
            isFilterReady = CommonConstant.C_YN_Y;
        });

        /**
         * 申请特批
         */
        $('#applySpecial').click(function(event) {
            var onOk = function (item, Dialog) {
                if($("#docketRem").val() == ""){
                    top.$.ligerDialog.SQalert({content: "发起特批流程原因为空", SQ_type: "warning"});
                    return false;
                }
                confirmBtn(CommonConstant.C_YN_Y);
                Dialog.hide();
            };
            var onCancel = function (item, Dialog) {
                Dialog.hide();
            };
            var len = ligerGrid_heguijigou.getData().length;
            var selectedRows = ligerGrid_heguijigou.getSelectedRows();
            if(len > 0 && !(selectedRows.length > 0)){
                //一、（强校验）  1.重卡项目类型：城配业务、传统业务    二、（弱校验）  1.专车事 业部项目类型：客车业务  2.新能源汽车项目类型：城配业务 3.其他
                if(isCheckRouteFlag == 1){
                    if(!(isAllowNonIns == CommonConstant.C_YN_Y)){//特批
                        $.ligerDialog.SQopen({
                            width: 450,
                            title : '申请特批',
                            target : $('#capFundConfirm_form'),
                            buttons: [
                                {
                                    text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
                                },{
                                    text: "申请特批", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
                                }
                            ]
                        });
                    }else{
                        top.$.ligerDialog.SQalert({content: "无需发起特批或请取消机构选中状态后发起特批", SQ_type: "warning"});
                        return false; //验证不通过，不执行以下代码
                    }
                }else{
                    top.$.ligerDialog.SQalert({content: "无需发起特批或请取消机构选中状态后发起特批", SQ_type: "warning"});
                    return false; //验证不通过，不执行以下代码
                }
            }else{
                if((preInsId != "" && preInsId != null) && len == 0){
                    if(isCheckRouteFlag == 1){
                        var dataUn = ligerGrid_heguijigouUn.getData();
                        var spfg = 0;
                        if(dataUn.length != 0){
                            for (index in dataUn){
                                var gctDes = dataUn[index].gctDes;
                                var insId = dataUn[index].insId;
                                if(ProjectConstant.GCT_DES == gctDes && insId == preInsId){
                                    spfg = 1;
                                }
                            }
                        }
                        if(!(isAllowNonIns == CommonConstant.C_YN_Y) && spfg == 0){//特批
                            $.ligerDialog.SQopen({
                                width: 450,
                                title : '申请特批',
                                target : $('#capFundConfirm_form'),
                                buttons: [
                                    {
                                        text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
                                    },{
                                        text: "申请特批", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
                                    }
                                ]
                            });
                        }else{
                            top.$.ligerDialog.SQalert({content: "无需发起特批或请取消机构选中状态后发起特批", SQ_type: "warning"});
                            return false; //验证不通过，不执行以下代码
                        }
                    }
                }else{
                    top.$.ligerDialog.SQalert({content: "无需发起特批或请取消机构选中状态后发起特批", SQ_type: "warning"});
                    return false; //验证不通过，不执行以下代码
                }
            }
        });


        /**
         * 保存路由数据
         */
        $('#confirmBtn').click(function(event) {
            if(stats){
                return false;
            }
            var ligerForm = liger.get("formSet");
            if (!ligerForm.valid()) {
                top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var flag = validInfo();
            if(flag == false){
                return false;
            }
            var onOk = function (item, Dialog) {
                if($("#docketRem").val() == ""){
                    top.$.ligerDialog.SQalert({content: "发起特批流程原因为空", SQ_type: "warning"});
                    return false;
                }
                confirmBtn(CommonConstant.C_YN_Y);
                Dialog.hide();
            };
            var onCancel = function (item, Dialog) {
                Dialog.hide();
            };
            var len = ligerGrid_heguijigou.getData().length;
            var selectedRows = ligerGrid_heguijigou.getSelectedRows();
            if(isFilterReady == CommonConstant.C_YN_Y && len > 0 && !(selectedRows.length > 0)){
                //一、（强校验）  1.重卡项目类型：城配业务、传统业务    二、（弱校验）  1.专车事 业部项目类型：客车业务  2.新能源汽车项目类型：城配业务 3.其他
                if(isCheckRouteFlag == 1){
                    if(!(isAllowNonIns == CommonConstant.C_YN_Y)){//特批
                        $.ligerDialog.SQopen({
                            width: 450,
                            title : '申请特批',
                            target : $('#capFundConfirm_form'),
                            buttons: [
                                {
                                    text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
                                },{
                                    text: "申请特批", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
                                }
                            ]
                        });
                    }else{
                        confirmBtn(CommonConstant.C_YN_N);
                    }
                }else{
                    confirmBtn(CommonConstant.C_YN_N);
                }
            }else if(!(isFilterReady == CommonConstant.C_YN_Y)){
                top.$.ligerDialog.SQalert({content: "请先筛选机构", SQ_type: "warning"});
                return;
            }else{
                if((preInsId != "" && preInsId != null) && len == 0){
                    if(isCheckRouteFlag == 1){
                        var dataUn = ligerGrid_heguijigouUn.getData();
                        var spfg = 0;
                        if(dataUn.length != 0){
                            for (index in dataUn){
                                var gctDes = dataUn[index].gctDes;
                                var insId = dataUn[index].insId;
                                if(ProjectConstant.GCT_DES == gctDes && insId == preInsId){
                                    spfg = 1;
                                }
                            }
                        }
                        if(!(isAllowNonIns == CommonConstant.C_YN_Y) && spfg == 0){//特批
                            $.ligerDialog.SQopen({
                                width: 450,
                                title : '申请特批',
                                target : $('#capFundConfirm_form'),
                                buttons: [
                                    {
                                        text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
                                    },{
                                        text: "申请特批", onclick: onOk, type: 'ok', cls: 'l-dialog-btn-ok'
                                    }
                                ]
                            });
                        }else{
                            confirmBtn(CommonConstant.C_YN_N);
                        }
                    }
                }else{
                    confirmBtn(CommonConstant.C_YN_N);
                }
            }
        });

        function confirmBtn(spemak) {
            var onCancel = function (item, Dialog) {
                Dialog.hide();
            };
            var onConfirmBtn = function (item, Dialog) {
                Dialog.hide();
                save(spemak);
            };
            if(!StringUtils.isEmpty($("#routeId").val())){
                $.ligerDialog.SQopen({
                    width: 450,
                    title : '友情提示',
                    target : $('#confirm_form'),
                    buttons: [
                        {
                            text: "确认", onclick: onConfirmBtn, type: 'ok', cls: 'l-dialog-btn-ok'
                        },{
                            text: "取消", onclick: onCancel, type: 'cancel', cls: 'l-dialog-btn-no'
                        }
                    ]
                });
            }else{
                save(spemak);
            }
        }

        function save(marks) {
            var ligerForm = liger.get("formSet");
            if (!ligerForm.valid()) {
                top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var flag = validInfo();
            if(flag == false){
                return false;
            }
            var data = ligerForm.getData();
            var carInfoList = JSON.stringify(ligerGrid_chanpin.getData());
            var feeList = JSON.stringify(ligerGrid_baojia.getData());
            var jigou = ligerGrid_heguijigou.getData();
            if(ligerGrid_heguijigou.getDeleted() != undefined || ligerGrid_heguijigou.getDeleted() != null){
                jigou = jigou.concat(ligerGrid_heguijigou.getDeleted());
            }
            if(ligerGrid_heguijigouUn.getDeleted() != undefined || ligerGrid_heguijigouUn.getDeleted() != null){
                jigou = jigou.concat(ligerGrid_heguijigouUn.getDeleted());
            }
            jigou = jigou.concat(ligerGrid_heguijigouUn.getData());
            var insResList = JSON.stringify(jigou);
            data["id"] = $("#routeId").val();
            data["prjId"] = prjId;
            data["isSplMfr"] = isSplMfr;
            data["channel"] = CommonConstant.C_YN_N;
            if(marks == CommonConstant.C_YN_Y){
                data["isSpecial"] = CommonConstant.C_YN_Y;
                data["reason"] = $("#docketRem").val();
                var docArray = JSON.stringify(getUploadResultParams());
                data["docArray"] = docArray;
            }else{
                data["isSpecial"] = CommonConstant.C_YN_N;
            }
            data["carInfoList"] = carInfoList;
            data["feeList"] = feeList;
            data["insResList"] = insResList;
            var selectedRows = ligerGrid_heguijigou.getSelectedRows();
            if(selectedRows.length > 0){
                data["checkedInsId"] = selectedRows[0].insId;
                data["checkedInsCode"] = selectedRows[0].insCode;
                data["checkedInsNm"] = selectedRows[0].insNm;
            }
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                data:data,
                url: '<%=path%>/insroute/insRouteBscInfo/save.do',
                beforeSend: function () {
                    stats = true;
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success:function(msg){
                    wait_dialog.close();
                    stats = false;
                    if(msg.success == CommonConstant.C_YN_Y){
                        $("#routeId").val(msg.data.id);
                        var selectid= parent.$("#isInsBiz").ligerGetComboBoxManager();
                        var cntTypCdId= parent.$("#cntTypCd").ligerGetComboBoxManager();
                        if(selectedRows.length > 0){
                            selectid.setValue(1);
                            selectid.setText("是");
                            parent.$("#isInsBiz").val(1);
                            parent.$("#fundRasInsNmDiv").show();
                            parent.$("#fundRasInsNm").html(selectedRows[0].insNm);
                            parent.$("#fundRasInsId").val(selectedRows[0].insId);
                            parent.$("#insCode").val(selectedRows[0].insCode);
                            parent.insCodeCheck = selectedRows[0].insCode;
                            if(ProjectConstant.PRJ_INS_CODE_ICBC == selectedRows[0].insCode){
                                var isHaveUpStruct = parent.$("#isHaveUpStruct").ligerGetComboBoxManager();
                                isHaveUpStruct.setValue(0);
                                isHaveUpStruct.setText("否");
                                parent.$("#isHaveUpStructDiv").show();
                            }else{
                                parent.$("#isHaveUpStructDiv").hide();
                            }
                            if(ProjectConstant.PRJ_INS_CODE_CCBANKTB == selectedRows[0].insCode){
                                cntTypCdId.setValue(1);
                                cntTypCdId.setText("电子");
                                parent.$("#cntTypCd").val(1);
                            }else if(parent.$("#cstTypCd").val() == ProjectConstant.CST_TYP_CD_LP && ProjectConstant.PRJ_INS_CODE_CCBANKTB != selectedRows[0].insCode){
                                cntTypCdId.setValue(2);
                                cntTypCdId.setText("纸质");
                                parent.$("#cntTypCd").val(2);
                            }
                            if (msg.data.sysInsTabCfgVO != null){
                                if(parent.pageInTab.isTabItemExist("tabM")) {
                                    parent.pageInTab.removeTabItem("tabM");
                                }
                                parent.pageInTab.addTabItem({
                                    text: msg.data.sysInsTabCfgVO.title,
                                    tabid: 'tabM',
                                    showClose: false,
                                    url: '<%=path%>/project/prjBscInfoInsDistribute/toPrjBscInsEditPage.do?prjId='+prjId,
                                });
                            }else{
                                parent.pageInTab.removeTabItem("tabM");
                            }
                        }else{
                            selectid.setValue(0);
                            selectid.setText("否");
                            parent.$("#isInsBiz").val(0);
                            //parent.$("#fundRasInsNmDiv").hide();
                            parent.$("#fundRasInsNm").html("");
                            parent.$("#fundRasInsId").val("");
                            parent.$("#insCode").val("");
                            parent.insCodeCheck = "";
                            parent.$("#isHaveUpStructDiv").hide();
                            parent.pageInTab.removeTabItem("tabM");
                        }
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        if(marks == CommonConstant.C_YN_Y){
                            parent.detailFlag = true;
                            parent.fromCAFlag = false;
                            parent.fromCMFlag = false;
                            parent.$("#savePrjBscInfoBtn").hide();
                            parent.$("#cancelBtn").hide();
                            parent.$("#chooseCst").hide();
                            parent.pageInTab.setTabItemSrc("tabP", "<%=path%>/insroute/insRouteBscInfo/toMainPage.do?prjId=" + prjId + "&&detailFlag=" + true);
                            var callback=GET_W2Wcallback();
                            if(callback) callback();
                            var TAB=top.mainApp.parentTab;
                            var currentTabid=TAB.getSelectedTabItemID();
                            top.tab.removeTabItem(currentTabid);
                        }
                        ligerGrid_chanpin.reload();
                        $.ligerDialog.hide();
                    }else{
                        top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        }
        initData();
        contrlData();
    })

        function initData(){
            var form = new liger.get("formSet");
            form.setData({
                isBp:${insRouteBscInfoVO.isBp},
                isFarmer:${insRouteBscInfoVO.isFarmer},
                isPreInt:${insRouteBscInfoVO.isPreInt},
                lsPdUntCd:${insRouteBscInfoVO.lsPdUntCd},
                isCheckOut:${insRouteBscInfoVO.isCheckOut},
                isLic:${insRouteBscInfoVO.isLic},
                isLicAgain:${insRouteBscInfoVO.isLicAgain},
                contAmt:${insRouteBscInfoVO.contAmt},
                fee63:${fee63},
                fee64:${fee64}
            });
            setRgnProvCdUpdataValue('${insRouteBscInfoVO.rgnPrCd}');
            setRgnCityCdUpdataValue('${insRouteBscInfoVO.rgnCyCd}');

            var checkOutDt = '${insRouteBscInfoVO.checkOutDt}';
            var licDt = '${insRouteBscInfoVO.licDt}';
            var licAgainDt = '${insRouteBscInfoVO.licAgainDt}';

            if(checkOutDt != ""){
                $("#checkOutDt").val(DateUtils.formatDate(new Date('${insRouteBscInfoVO.checkOutDt}'),DateUtils.YYYY_MM_DD));
            }
            if(licDt != ""){
                $("#licDt").val(DateUtils.formatDate(new Date('${insRouteBscInfoVO.licDt}'),DateUtils.YYYY_MM_DD));
            }
            if(licAgainDt != ""){
                $("#licAgainDt").val(DateUtils.formatDate(new Date('${insRouteBscInfoVO.licAgainDt}'),DateUtils.YYYY_MM_DD));
            }

            if(detailFlag == 'true'){//详情
                $("#addBtn").hide();
                $("#addGuacheBtn").hide();
                $("#detailBtn").hide();
                $("#clearBtn").hide();
                $("#filterBtn").hide();
                if (liger.get("isCheckOut")) {
                    liger.get("isCheckOut").setDisabled(true);
                }
                if (liger.get("isLic")) {
                    liger.get("isLic").setDisabled(true);
                }
                if (liger.get("isFarmer")) {
                    liger.get("isFarmer").setDisabled(true);
                }
                if (liger.get("isLicAgain")) {
                    liger.get("isLicAgain").setDisabled(true);
                }
                if (liger.get("checkOutDt")) {
                    liger.get("checkOutDt").setDisabled(true);
                }
                if (liger.get("licDt")) {
                    liger.get("licDt").setDisabled(true);
                }
                if (liger.get("licAgainDt")) {
                    liger.get("licAgainDt").setDisabled(true);
                }
                if (liger.get("fee63")) {
                    liger.get("fee63").setDisabled(true);
                }
                if (liger.get("rgnProvCd")) {
                    liger.get("rgnProvCd").setDisabled(true);
                }
                if (liger.get("rgnCityCd")) {
                    liger.get("rgnCityCd").setDisabled(true);
                }
                if (liger.get("lsPd")) {
                    liger.get("lsPd").setDisabled(true);
                }
                if (liger.get("lsPdUntCd")) {
                    liger.get("lsPdUntCd").setDisabled(true);
                }
                if (liger.get("annIntRatePct")) {
                    liger.get("annIntRatePct").setDisabled(true);
                }
                if (liger.get("isBp")) {
                    liger.get("isBp").setDisabled(true);
                }
                $("#detailres_div").show();
            }
        }

        function contrlData(){
            var isCheckOut = $("#isCheckOut").val();
            var isLic = $("#isLic").val();
            var isLicAgain = $("#isLicAgain").val();
            if(isCheckOut == CommonConstant.C_YN_Y){
                $("#checkOutDtdiv").show();
            }else{
                $("#checkOutDt").val("");
                $("#checkOutDtdiv").hide();
            }
            if(isLic == CommonConstant.C_YN_Y){
                $("#licDtdiv").show();
            }else{
                $("#licDt").val("");
                $("#licDtdiv").hide();
            }
            if(isLicAgain == CommonConstant.C_YN_Y){
                $("#licAgainDtdiv").show();
            }else{
                $("#licAgainDt").val("");
                $("#licAgainDtdiv").hide();
            }
        }
        function validInfo(){
            var isCheckOut = $("#isCheckOut").val();
            var isLic = $("#isLic").val();
            var isFarmer = $("#isFarmer").val();
            var isLicAgain = $("#isLicAgain").val();
            var fee63 = $("#fee63").val();
            var rgnProvCd = $("#rgnProvCd").val();
            var rgnCityCd = $("#rgnCityCd").val();
            var lsPd = $("#lsPd").val();
            var lsPdUntCd = $("#lsPdUntCd").val();
            var annIntRatePct = $("#annIntRatePct").val();
            var isBp = $("#isBp").val();
            var contAmt = $("#contAmt").val();
            var ligerGrid_chanpin = liger.get("grid_chanpin");
            var ligerGrid_baojia = liger.get("grid_baojia");
            var carInfoList = ligerGrid_chanpin.getData();
            var feeList = ligerGrid_baojia.getData();
            if(rgnProvCd == ""){
                top.$.ligerDialog.SQalert({content: "区域-省为空", SQ_type: "error"});
                return false;
            }
            if(isFarmer == ""){
                top.$.ligerDialog.SQalert({content: "是否农民为空", SQ_type: "error"});
                return false;
            }
            if(rgnCityCd == ""){
                top.$.ligerDialog.SQalert({content: "区域-市为空", SQ_type: "error"});
                return false;
            }
            if(lsPdUntCd == ""){
                top.$.ligerDialog.SQalert({content: "期数单位为空", SQ_type: "error"});
                return false;
            }
            if(isBp == ""){
                top.$.ligerDialog.SQalert({content: "是否包牌为空", SQ_type: "error"});
                return false;
            }
            if(lsPd == "" || !(lsPd>0)){
                top.$.ligerDialog.SQalert({content: "期数为空", SQ_type: "error"});
                return false;
            }
            if(annIntRatePct == "" || (annIntRatePct<0)){
                top.$.ligerDialog.SQalert({content: "年利率为空", SQ_type: "error"});
                return false;
            }
            if(contAmt == "" || !(contAmt>0)){
                top.$.ligerDialog.SQalert({content: "合同额为空", SQ_type: "error"});
                return false;
            }
            if(fee63 == ""){
                top.$.ligerDialog.SQalert({content: "请填写主票金额", SQ_type: "error"});
                return false;
            }
            if(!(fee63>0)){
                top.$.ligerDialog.SQalert({content: "请填写准确主票金额", SQ_type: "error"});
                return false;
            }
            //新增对所有设备的“主票金额”进行校验
            //当主票金额≥设备预估车价*30%时，主票金额校验通过
            if(fee63 < contAmt*0.3){
                top.$.ligerDialog.SQalert({content: "请准确维护主票金额！", SQ_type: "error"});
                return false;
            }
            if(isCheckOut == CommonConstant.C_YN_Y){
                if($("#checkOutDt").val() == ""){
                    top.$.ligerDialog.SQalert({content: "开票时间为空", SQ_type: "error"});
                    return false;
                }
            }
            if(isLic == CommonConstant.C_YN_Y){
                if($("#licDt").val() == ""){
                    top.$.ligerDialog.SQalert({content: "上牌时间为空", SQ_type: "error"});
                    return false;
                }
            }
            if(isLicAgain == CommonConstant.C_YN_Y){
                if($("#licAgainDt").val() == ""){
                    top.$.ligerDialog.SQalert({content: "再次上牌时间为空", SQ_type: "error"});
                    return false;
                }
            }
            if(!(carInfoList.length>0)){
                top.$.ligerDialog.SQalert({content: "设备信息为空", SQ_type: "error"});
                return false;
            }else{
                for (index in carInfoList){
                    var guidePc = carInfoList[index].guidePc;
                    var prdQty = carInfoList[index].prdQty;
                    var prdTypCd = carInfoList[index].prdTypCd;
                    var prdCd = carInfoList[index].prdCd;
                    var prdId = carInfoList[index].prdId;
                    var modelId = carInfoList[index].modelId;
                    var brId = carInfoList[index].brId;
                    if(prdCd ==  "2"){
                        if(!(guidePc>0) || !(prdQty>0) || prdId == "" || prdId == null){
                            top.$.ligerDialog.SQalert({content: "设备信息不完整", SQ_type: "error"});
                            return false;
                        }
                    }else{
                        if(!(guidePc>0) || !(prdQty>0)
                            || prdId == "" || prdId == null
                            || modelId == "" || modelId == null
                            || brId == "" || brId == null){
                            top.$.ligerDialog.SQalert({content: "设备信息不完整", SQ_type: "error"});
                            return false;
                        }
                    }
                }
            }
            if(!(feeList.length>0)){
                top.$.ligerDialog.SQalert({content: "费用项信息为空", SQ_type: "error"});
                return false;
            }else{
                for (index in feeList){
                    var feeTypCd = feeList[index].feeTypCd;
                    if(ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_01 == feeTypCd){
                        if(feeList[index].calBaseCd != 1){
                            top.$.ligerDialog.SQalert({content: "首期计算基数只能是合同额", SQ_type: "error"});
                            return false;
                        }
                    }
                }
                if(CommonConstant.C_YN_Y == isSplMfr){
                    for (index in feeList){
                        var feeTypCd = feeList[index].feeTypCd;
                        var feeAmt = feeList[index].feeAmt;
                        if(ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_52 == feeTypCd){
                            if(!(feeAmt>0)){
                                top.$.ligerDialog.SQalert({content: "厂商贴息不大于0", SQ_type: "error"});
                                return false;
                            }
                        }
                    }
                }
            }
            var prdList = ligerGrid_chanpin.getData();
            var feeList = ligerGrid_baojia.getData();
            var mediationFeeAmt = 0;
            var firstAmt = 0;
            for(index in prdList){
                mediationFeeAmt += prdList[index].mediationFeeAmt;
            }
            for(index in feeList){
                if(feeList[index].feeTypCd == '01'){
                    firstAmt =  feeList[index].feeAmt;
                }
            }
            if(parseFloat(firstAmt)<parseFloat(mediationFeeAmt)){
                top.$.ligerDialog.SQalert({content: "首付金额不可低于调节费，请核实", SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
        }
    function toNonExponential(num) {
        var m = num.toExponential().match(/\d(?:\.(\d*))?e([+-]\d+)/);
        return num.toFixed(Math.max(0, (m[1] || '').length - m[2]));
    }
    </script>
</body>
</html>
